package com.dianjing.dianqun.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dianjing.dianqun.common.ResponseData;
import com.dianjing.dianqun.common.base.BaseRestController;
import com.dianjing.dianqun.model.Site;
import com.dianjing.dianqun.service.SiteService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @date : 2017年10月9日
 * 
 * @author: baoyongtao
 * 
 * @see :
 * 
 */
@Controller
@RequestMapping("/site")
public class SiteController extends BaseRestController {

	@Autowired
	private SiteService dianQunSiteService;

	@RequestMapping("/list")
	public String list(HttpServletRequest request) {
		return "site/list";
	}

	@RequestMapping("/getSiteList.json")
	@ResponseBody
	public Object getSiteList(HttpServletRequest request, @RequestParam(defaultValue = "0") Integer pageNum,
			@RequestParam(defaultValue = "20") Integer pageSize,@RequestParam (defaultValue="")String keyword) {
		PageHelper.startPage(pageNum, pageSize, true);
		PageInfo<Site> page = new PageInfo<Site>(dianQunSiteService.findByQuery(keyword));
		ResponseData data = new ResponseData(ResponseData.STATUS_OK, "请求成功", page);
		return data;
	}
}
